/**
 * [地图工具类]
 * @AuthorHTL 
 * @DateTime  2017-07-04T09:53:28+0800
 * return overlay
 */
(function(window, document){
	var OLGIS = function(){
		this.version = '0.1';
		this.map = null;
		this.projection = 'EPSG:4326';
		this.center = [116.37, 39.41];
		this.tdtLayer = null;//影像图
		this.baseLayer = null;//矢量图（OSM底图）
		this.dxtLayer = null;//地形图
		this.wptLayer = null;//卫片图
		this.sxtLayer = null;//水系图
		this.zwtLayer = null;//植物图
		this.dwtLayer = null;//动物图
		this.gnqhtLayer = null;//功能区划图
		this.gnqwtLayer = null;//功能区位图
		this.rhyxLayer = null;//融合影像2.5m
		this.vector = null;
	};

	OLGIS.prototype = {
		//默认WGS84
		initMap: function(id) {
			var view = new ol.View({
				projection: this.projection,
				//center: ol.proj.transform(this.center, 'EPSG:4326', 'EPSG:3857'),
				center: this.center,
				zoom: 6
			});
			this.map = new ol.Map({
                layers: [],
                view: view,
                target: id,
                controls: ol.control.defaults({
                	attribution: false,
                	zoom: false
                })
            });
			
		},
		addBaseLayer: function() {
			baseLayer = new ol.layer.Tile({
				source: new ol.source.OSM()
			});
			this.map.addLayer(baseLayer);
		},
		addTDTLayer: function() {
			tdtLayer = new ol.layer.Tile({
				source: new ol.source.TileArcGISRest({
					//
                    url:'http://services.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer',
                    crossOrigin: 'anonymous'
				})
			});
			this.map.addLayer(tdtLayer);
		},
		addWFSLayer: function(){
			vector = new ol.layer.Vector({
		      source: new ol.source.Vector({
		        format: new ol.format.GeoJSON(),
		        url: 'http://localhost:9000/geoserver/wfs?service=wfs&version=1.1.0&request=GetFeature&typeNames=nyc_roads:nyc_roads&outputFormat=application/json&srsname=EPSG:4326'
		      }),
		      style: function(feature, resolution) {
		        return new ol.style.Style({
		          stroke: new ol.style.Stroke({
		            color: 'blue',
		            width: 1
		          })
		        });
		      }
		    });
			this.map.addLayer(vector);
		},
		//地形图
		addDXT:function(){
//			 var format = 'image/png';
//		      var bounds = [132.08686470556336, 46.66014672834982,
//		                    133.03356118783964, 46.980013059879106];
//			
//		      dxtLayer = new ol.layer.Tile({
//		        source: new ol.source.TileWMS({
//		            url: 'http://127.0.0.1:8080/geoserver/wlp/wms',
//		            params: {'FORMAT': format, 
//		                     'VERSION': '1.1.1',
//		                     tiled: true,
//		                  STYLES: '',
//		                  LAYERS: 'wlp:dxt',
//		            }
//		       })
//		      });
//			this.map.addLayer(dxtLayer);
			
			
			dxtLayer = new ol.layer.Tile({
	            source: new ol.source.TileWMS({
	                url: 'http://localhost:8080/geoserver/gwc/service/wms?',
	                params: {
	                    'FORMAT': "image/png",
	                    'VERSION': '1.1.1',
	                    tiled: true,
	                    STYLES: '',
	                    LAYERS: 'wlp:cacheTest',
	                }
	            })
	        });
			this.map.addLayer(dxtLayer);
		},
		//卫片图
		addWPT:function(){
			var format = 'image/png';
		    var bounds = [132.1803953511738, 46.71247826561369,
		                    132.97943159504618, 46.90389702406175];
		    wptLayer = new ol.layer.Tile({
				source: new ol.source.TileWMS({
		          url: 'http://localhost:8080/geoserver/wlp/wms',
		          params: {'FORMAT': format, 
		                   'VERSION': '1.1.1',
		                   tiled: true,
		                STYLES: '',
		                LAYERS: 'wlp:wlp_wpt',
		          }
		        })
		      });
			this.map.addLayer(wptLayer);
		},
		//水系图
		addSXT:function(){
			var format = 'image/png';
		    var bounds = [132.07459813226305, 46.64622604520168,
		                    133.05506712896022, 46.98569287170365];
		    
		    sxtLayer = new ol.layer.Tile({
		    	source: new ol.source.TileWMS({
		            url: 'http://localhost:8080/geoserver/wlp/wms',
		            params: {'FORMAT': format, 
		                     'VERSION': '1.1.1',
		                     tiled: true,
		                  STYLES: '',
		                  LAYERS: 'wlp:sxt',
		            }
		          })
		      });
			this.map.addLayer(sxtLayer);
		},
		//植物图
		addZWT:function(){
			var format = 'image/png';
		    var bounds = [132.07309805655825, 46.6532130433919,
		                    133.04802919809484, 46.98154208921369];
		    zwtLayer = new ol.layer.Tile({
		    	source: new ol.source.TileWMS({
		            url: 'http://localhost:8080/geoserver/wlp/wms',
		            params: {'FORMAT': format, 
		                     'VERSION': '1.1.1',
		                     tiled: true,
		                  STYLES: '',
		                  LAYERS: 'wlp:zwt',
		            }
		          })
		      });
			this.map.addLayer(zwtLayer);
		},
		//动物图
		addDWT:function(){
			var format = 'image/png';
		    var bounds = [132.07138597658698, 46.652038928807215,
		                    133.04875936363038, 46.98699662777616];
		    dwtLayer = new ol.layer.Tile({
		    	source: new ol.source.TileWMS({
		            url: 'http://localhost:8080/geoserver/wlp/wms',
		            params: {'FORMAT': format, 
		                     'VERSION': '1.1.1',
		                     tiled: true,
		                  STYLES: '',
		                  LAYERS: 'wlp:dwt',
		            }
		         })
		      });
			this.map.addLayer(dwtLayer);
		},
		//功能区划图
		addGNQ:function(){
			var format = 'image/png';
		    var bounds = [132.0731342786162, 46.62625334594499,
		                    133.05699634604846, 46.96372365614827];
		    gnqhtLayer = new ol.layer.Tile({
		    	source: new ol.source.TileWMS({
		            url: 'http://localhost:8080/geoserver/wlp/wms',
		            params: {'FORMAT': format, 
		                     'VERSION': '1.1.1',
		                     tiled: true,
		                  STYLES: '',
		                  LAYERS: 'wlp:gnq',
		            }
		          })
		      });
			this.map.addLayer(gnqhtLayer);
		},
		//功能区位图
		addGNQWT:function(){
			 var format = 'image/png';
		      var bounds = [132.07611737785095, 46.625089207967115,
		                    133.05510319034002, 46.96381812141769];
		      gnqwtLayer = new ol.layer.Tile({
		    	  source: new ol.source.TileWMS({
		              url: 'http://localhost:8080/geoserver/wlp/wms',
		              params: {'FORMAT': format, 
		                       'VERSION': '1.1.1',
		                       tiled: true,
		                    STYLES: '',
		                    LAYERS: 'wlp:gnqwt',
		              }
		            })
			      });
				this.map.addLayer(gnqwtLayer);
		},
		//融合影响2.5m
		addRHYX:function(){
			var format = 'image/png';
		    var bounds = [131.50732073519941, 46.78146370409238,
		                    131.96193137620818, 47.10914615851389];
		    rhyxLayer = new ol.layer.Tile({
		    	source: new ol.source.TileWMS({
		            url: 'http://localhost:8080/geoserver/wlp/wms',
		            params: {'FORMAT': format, 
		                     'VERSION': '1.1.1',
		                     tiled: true,
		                  STYLES: '',
		                  LAYERS: 'wlp:rhyx',
		            }
		          })
		      });
			this.map.addLayer(rhyxLayer);
		}
		
			
		
	}
	window.OLGIS = OLGIS;
})(window, document);
